package zuoye3;

import java.util.Scanner;

public class Cinema {
	private Window w1;
	private Window w2;
	private Guest g1;
	
	public void ticket_buy() {
		if (Window.ticket_Surplus > 0) {
			System.out.println("选择窗口:1,2。");
			int select = 0;
			Scanner sc = new Scanner(System.in);
			while (select != 1 && select != 2) {
				select = sc.nextInt();
				if (select != 1 && select != 2) {
					System.out.println("输入无效。");
				}
				
			}
			System.out.println("要买多少票？当前总票数：" + Window.ticket_Surplus + "。"
					+"窗口1："+w1.getTicket_Now()
					+"   "
					+"窗口2："+w2.getTicket_Now()
								
					);
			int ticket_Buy=-1;
			ticket_Buy=sc.nextInt();
			if(select==1) {
				while(ticket_Buy>w1.getTicket_Now()) {
					System.out.println("窗口票数不足，重新输入");
					ticket_Buy=sc.nextInt();
				}
				w1.setTicket_Now((-1)*ticket_Buy);
				Window.setTicket_Surplus((-1)*ticket_Buy);
			}
			else if(select==2) {
				while(ticket_Buy>w2.getTicket_Now()) {
					System.out.println("窗口票数不足，重新输入");
					ticket_Buy=sc.nextInt();
				}
				w2.setTicket_Now((-1)*ticket_Buy);
				Window.setTicket_Surplus((-1)*ticket_Buy);
				
			}
			g1.setTicketBuy(ticket_Buy);
			System.out.println("购买完成！");
		} else {
			System.out.println("没票了。。。");
		}
	}

	public void ticket_sendback() {
		if(g1.getTicketBuy()>0) {
			System.out.println("退多少票？");
			int ticket_Sendback=-1;
			Scanner sc = new Scanner(System.in);
			ticket_Sendback=sc.nextInt();
			while(ticket_Sendback<0||ticket_Sendback>g1.getTicketBuy()) {
				if(ticket_Sendback>g1.getTicketBuy()) {
					System.out.println("你没有这么多票，重新输入。");
					
				}
				else if(ticket_Sendback<0) {
					System.out.println("输入无效，重新输入。");
					
				}
				ticket_Sendback=sc.nextInt();
			}
			int sum=ticket_Sendback+w1.getTicket_Now()+w2.getTicket_Now();
			w1.setTicket_Now((-1)*w1.getTicket_Now());
			w2.setTicket_Now((-1)*w2.getTicket_Now());
			w1.setTicket_Now(sum/2);
			w2.setTicket_Now(sum-sum/2);
			Window.setTicket_Surplus(ticket_Sendback);
			System.out.println("完成。");
		}
		else {
			System.out.println("你没有票。");
		}
	}
	Cinema(Guest g){
		w1=new Window();
		w2=new Window();
		g1=g;
	}
	
}